<template>
  <!-- 任务日志详细 -->
  <el-dialog title="任务详细" :visible.sync="visible" width="700px" append-to-body @colsed="reset">
    <el-form ref="form" :model="form" label-width="120px" size="mini">
      <el-row>
        <el-col :span="12">
          <el-form-item label="任务名称：">{{ form.jobName }}</el-form-item>
          <el-form-item label="任务分组：">{{ jobGroupFormat(form) }}</el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="调用目标方法：">{{ form.invokeTarget }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="cron表达式：">{{ form.cronExpression }}</el-form-item>
          <el-form-item label="任务状态：">
            <div v-if="form.status === '0'">正常</div>
            <div v-else-if="form.status === '1'">暂停</div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getJob } from "@/api/monitor/job";

export default {
  name: "detail",
  props: {
    // 任务组名字典
    jobGroupOptions: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      id: undefined,
      visible: false,
      form: {
        jobName: undefined,
        jobGroup: undefined,
        invokeTarget: undefined,
        cronExpression: undefined,
        misfirePolicy: 1,
        concurrent: 1,
        status: "0"
      }
    }
  },
  methods: {
    init(id) {
      this.visible = true;
      this.id = id;
      if (id) {
        this.initData();
      }
    },
    initData() {
      getJob(this.id).then(response => {
        this.form = response;
      });
    },
    close() {
      this.visible = false;
    },
    // 表单重置
    reset() {
      this.id = undefined;
      this.form = {
        jobName: undefined,
        jobGroup: undefined,
        invokeTarget: undefined,
        cronExpression: undefined,
        misfirePolicy: 1,
        concurrent: 1,
        status: "0"
      };
    },
    // 任务组名字典翻译
    jobGroupFormat(row) {
      return this.selectDictLabel(this.jobGroupOptions, row.jobGroup);
    }
  }
}
</script>

<style scoped>

</style>
